const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    bg: cc.Node = undefined

    private scale:number = 1;

    
    // 网上找的适配背景的代码，很简单也很实用
    onLoad() {
        // 1. 先找到 SHOW_ALL 模式适配之后，本节点的实际宽高以及初始缩放值
        let srcScaleForShowAll = Math.min(cc.view.getCanvasSize().width / this.node.width, cc.view.getCanvasSize().height / this.node.height);
        let realWidth = this.node.width * srcScaleForShowAll;
        let realHeight = this.node.height * srcScaleForShowAll;

        // 2. 基于第一步的数据，再做缩放适配
        this.scale = this.node.scale = Math.max(cc.view.getCanvasSize().width / realWidth, cc.view.getCanvasSize().height / realHeight);
    }

    update(dt) {
        this.bg.x -= dt * 200
        if (this.bg.x <= -cc.winSize.width * this.scale) {
            this.bg.x = -(cc.winSize.width * this.scale - cc.winSize.width)
        }

    }
}
